package fm.jiecao.jcvideoplayer_lib;

import android.annotation.SuppressLint;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.List;


public class PopuwindowAdapter extends RecyclerView.Adapter<PopuwindowAdapter.MyViewHolder> {
	private List<Float> list;
	public PopuwindowAdapter(Context context,List<Float> list) {
		// TODO Auto-generated constructor stub
		this.list=list;
	}

	@Override
	public MyViewHolder onCreateViewHolder( ViewGroup viewGroup, int position) {
		MyViewHolder viewHolder;
		View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_speed1, viewGroup, false);
		viewHolder = new MyViewHolder(view);
		return viewHolder;
	}

	@Override
	public void onBindViewHolder(MyViewHolder myViewHolder, @SuppressLint("RecyclerView") int position) {
		myViewHolder.name.setText(String.valueOf(list.get(position)));
		if(myViewHolder.view_lin == null || myViewHolder.item_view==null){
			return;
		}
		myViewHolder.item_view.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {
				mOnItemClickListener.onItemClick(view, list.get(position), position);
			}
		});//设置监听器
		if(position==list.size()-1){
			myViewHolder.view_lin.setVisibility(View.GONE);
		}else{
			myViewHolder.view_lin.setVisibility(View.VISIBLE);
		}
	}

	@Override
	public int getItemCount() {
		return list.size();
	}

	//自定义一个回调接口来实现Click和LongClick事件
	public interface OnItemClickListener  {
		void onItemClick(View v, float viewName, int position);
	}

	private OnItemClickListener mOnItemClickListener;//声明自定义的接口

	//定义方法并传给外面的使用者
	public void setOnItemClickListener(OnItemClickListener  listener) {
		this.mOnItemClickListener = listener;
	}

	class MyViewHolder extends RecyclerView.ViewHolder {
		TextView name;
		View view_lin;
		LinearLayout item_view;
		public MyViewHolder( View itemView) {
			super(itemView);
			name=itemView.findViewById(R.id.file_name);
			view_lin=itemView.findViewById(R.id.view_lin);
			item_view=itemView.findViewById(R.id.item_view);
		}
	}

}
